%function data = readUDP(lport)
function [servo_angles, conf, time] = readUDP(lport)
%*=+--+=#=+--      UAS Severe Weather Simulation Softeware        --+=#=+--+=#*%
%          Copyright (C) 2013 Regents of the University of Colorado.           %
%                             All Rights Reserved.                             %
%                                                                              %
%    This program is free software: you can redistribute it and/or modify      %
%    it under the terms of the GNU General Public License version 2 as         %
%    published by the Free Software Foundation.                                %
%                                                                              %
%    This program is distributed in the hope that it will be useful,           %
%    but WITHOUT ANY WARRANTY; without even the implied warranty of            %
%    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the             %
%    GNU General Public License for more details.                              %
%                                                                              %
%    You should have received a copy of the GNU General Public License         %
%    along with this program.  If not, see <http://www.gnu.org/licenses/>.     %
%                                                                              %
%           Jack Elston                                                        %
%           elstonj@colorado.edu                                               %
%                                                                              %
%*=+--+=#=+--                 --+=#=+--+=#=+--                    --+=#=+--+=#*%

	udp=pnet('udpsocket',lport);
	pnet(udp,'setreadtimeout',1.0);
	try,
		% Wait/Read udp packet to reed buffer
		len=pnet(udp,'readpacket');
		if len == 56,
			servos=pnet(udp,'read',[1 20],'int16')';
			time=pnet(udp,'read',1,'uint32');
			conf=pnet(udp,'read',1,'uint32');
			servo_angles=servos(2:2:end);
			servo_pulses=servos(1:2:end);
		end
	end

	% On break or error close udpconnection and figure window.
	pnet(udp,'close');
